import mock from '../index'
import {
  food,
  bathe,
  love,
  kalaOK
} from './data/shopList-data'
/**
 * api mock 店铺列表
 */
const map = {
  1: food,
  2: bathe,
  3: love,
  4: kalaOK,
  5:[],
  6:[],
  7:[],
  8:[],
  9:[],
}
for (let i = 1; i < 10; i++) {
  const reg = new RegExp(`\/categories\/${i}\/shops`)
  mock.Mock(reg, 'get', (options) => {
    return getShopList(map[i], options)
  })
}

function getShopList(allList, options) {
  const limit = options.data._limit
  let page = options.data._page
  const total = allList.length
  const maxPage = Math.ceil(total / limit)
  if (page > maxPage) {
    page = maxPage
  }
  page--
  const start = page * limit
  let end = start + limit
  if (end > total - 1) {
    end = total - 1
  }
  return {
    total,
    page: page + 1,
    limit,
    maxPage,
    list: allList.slice(start, end)
  }
}